package com.chinaums.fsp.sdk.request;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;

import com.chinaums.fsp.base.pgt.TransType;
import com.chinaums.fsp.sdk.base.RequestData;
import com.chinaums.fsp.sdk.base.ResponseDataWrapper;
import com.chinaums.fsp.sdk.pgt.params.UplaodFileResponse;
import com.chinaums.fsp.sdk.pgt.params.UploadFileRequest;
/**
 * 直贴文件上传
 * @author hty
 *
 */
public class DraftUploadFile extends BaseRequest{
	public void test()throws Exception{
		PgtRequestFactory rf = FACTORY.factory();
		/**
		 * 地址换成http://127.0.0.1:8083/pgt-api/api/v1/draftUpload.json
		 * 
		 * 这边要替换成自己的文件
		 */
		
		File file = new File(DraftUploadFile.class.getClassLoader().getResource("142143.jpg").getPath());
		UploadFileRequest data = UploadFileRequest.newBuilder()
									.setFileName("1")
									.build();
		RequestData.Builder builder = this.createRequestDataBuilder();
		builder.setTransType(TransType.DRAFT_UPLOAD_FILE.getTransCode());
		rf.transType(TransType.DRAFT_UPLOAD_FILE.getTransCode())
		.responseClass(UplaodFileResponse.class)
		.data(data)
		;
		try{
			ResponseDataWrapper rdw = rf.post(file);
			String json = this.json(rdw);
			this.printToDraft(rdw);
		}catch(Exception e){
			System.out.println(e);
		}
		
	}

}
